package com.zheng.durid;

import com.zheng.durid.config.DruidSourceConfig;
import com.zheng.zk.Curator;
import org.apache.curator.framework.CuratorFramework;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

/**
 *  @author: zheng
 *  @Date: 2020-07-03 01:23
 *  @Description:
 */
@Component
public class InitConfig implements ApplicationRunner {
    @Override
    public void run(ApplicationArguments args) throws Exception {
        CuratorFramework curatorFramework= Curator.getCuratorFramework();
        byte[] bytes= curatorFramework.getData().forPath("/mysqlConfig");
        String config=new String(bytes);
        String [] configs=config.split(",");
        String url=configs[0];
        String userName=configs[1];
        String password=configs[2];
        DruidSourceConfig.setDataSource(url,userName,password);
        DruidSourceConfig.registListener();
    }
}
